package com.spacewiz13.algorithm.number;

import java.util.HashSet;
import java.util.Set;

/**
 * Given an array of integers, find if the array contains any duplicates. 
 * Your function should return true if any value appears at least twice in the array, 
 * and it should return false if every element is distinct.
 * @author David
 *
 */
public class ContainsDuplicate {
	
	public static void main(String[] args) {
		ContainsDuplicate bean = new ContainsDuplicate();
		int[] list = new int[]{1,2,2};
		System.out.println(bean.containsDuplicate(list));
	}
	
	
    public boolean containsDuplicate(int[] nums) {
    	Set<Integer> set = new HashSet<Integer>();
    	for(int num:nums){
    		set.add(num);
    	}
    	if(nums.length==set.size())
    		return false;
    	else
    		return true;
        
    }
}
